package com.fr.report.web.ui;

import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.util.Utils;
import com.fr.web.Repository;

public class NumberEditor extends FieldEditor
{
  private int maxIntegerLength = 32;
  private int maxDecimalLength = 16;
  private boolean allowDecimals = true;
  private boolean allowNegative = true;
  private double minValue = -1.797693134862316E+308D;
  private double maxValue = 1.7976931348623157E+308D;

  public String getXType()
  {
    return "number";
  }

  public int getMaxIntegerLength()
  {
    return this.maxIntegerLength;
  }

  public void setMaxIntegerLength(int paramInt)
  {
    this.maxIntegerLength = paramInt;
  }

  public int getMaxDecimalLength()
  {
    return this.maxDecimalLength;
  }

  public void setMaxDecimalLength(int paramInt)
  {
    this.maxDecimalLength = paramInt;
  }

  public boolean isAllowDecimals()
  {
    return this.allowDecimals;
  }

  public void setAllowDecimals(boolean paramBoolean)
  {
    this.allowDecimals = paramBoolean;
  }

  public boolean isAllowNegative()
  {
    return this.allowNegative;
  }

  public void setAllowNegative(boolean paramBoolean)
  {
    this.allowNegative = paramBoolean;
  }

  public double getMinValue()
  {
    return this.minValue;
  }

  public void setMinValue(double paramDouble)
  {
    this.minValue = paramDouble;
  }

  public double getMaxValue()
  {
    return this.maxValue;
  }

  public void setMaxValue(double paramDouble)
  {
    this.maxValue = paramDouble;
  }

  protected Object value2Config(Object paramObject)
  {
    return Utils.objectToNumber(paramObject, true);
  }

  public JSONObject createJSONConfig(Object paramObject, Repository paramRepository)
    throws JSONException
  {
    JSONObject localJSONObject = super.createJSONConfig(paramObject, paramRepository);
    localJSONObject.put("maxIntLength", getMaxIntegerLength()).put("maxDecLength", getMaxDecimalLength());
    if (!(isAllowDecimals()))
      localJSONObject.put("allowDecimals", isAllowDecimals());
    if (!(isAllowNegative()))
      localJSONObject.put("allowNegative", isAllowNegative());
    if (getMinValue() != -1.797693134862316E+308D)
      localJSONObject.put("minValue", getMinValue());
    if (getMaxValue() != 1.7976931348623157E+308D)
      localJSONObject.put("maxValue", getMaxValue());
    return localJSONObject;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if ((paramXMLableReader.isChildNode()) && (((paramXMLableReader.getTagName().equals("NumberAttr")) || ("Attribute".equals(paramXMLableReader.getTagName())))))
    {
      String str = null;
      if ((str = paramXMLableReader.getAttr("maxIntegerLength")) != null)
        setMaxIntegerLength(Integer.parseInt(str));
      if ((str = paramXMLableReader.getAttr("maxDecimalLength")) != null)
        setMaxDecimalLength(Integer.parseInt(str));
      if ((str = paramXMLableReader.getAttr("allowDecimals")) != null)
        setAllowDecimals(Boolean.valueOf(str).booleanValue());
      if ((str = paramXMLableReader.getAttr("allowNegative")) != null)
        setAllowNegative(Boolean.valueOf(str).booleanValue());
      if ((str = paramXMLableReader.getAttr("minValue")) != null)
        setMinValue(Double.parseDouble(str));
      if ((str = paramXMLableReader.getAttr("maxValue")) != null)
        setMaxValue(Double.parseDouble(str));
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("NumberAttr");
    if (getMaxIntegerLength() != 32)
      paramXMLPrintWriter.attr("maxIntegerLength", getMaxIntegerLength());
    if (getMaxDecimalLength() != 16)
      paramXMLPrintWriter.attr("maxDecimalLength", getMaxDecimalLength());
    if (!(isAllowDecimals()))
      paramXMLPrintWriter.attr("allowDecimals", isAllowDecimals());
    if (!(isAllowNegative()))
      paramXMLPrintWriter.attr("allowNegative", isAllowNegative());
    if (getMinValue() != -1.797693134862316E+308D)
      paramXMLPrintWriter.attr("minValue", getMinValue());
    if (getMaxValue() != 1.7976931348623157E+308D)
      paramXMLPrintWriter.attr("maxValue", getMaxValue());
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof NumberEditor) && (super.equals(paramObject)) && (this.maxIntegerLength == ((NumberEditor)paramObject).maxIntegerLength) && (this.maxDecimalLength == ((NumberEditor)paramObject).maxDecimalLength) && (this.allowDecimals == ((NumberEditor)paramObject).allowDecimals) && (this.allowNegative == ((NumberEditor)paramObject).allowNegative) && (this.minValue == ((NumberEditor)paramObject).minValue) && (this.maxValue == ((NumberEditor)paramObject).maxValue));
  }
}